package com.kevin.effective;

/**
 * @Description 2.当构造方法参数过多时使用builder模式
 * @Author Kevin
 * @Date: Created in  14:54 2019/12/12:
 * @Modified By:
 * @Email: tang.lx@topcheer.com
 */
public class Two {
    public static void main(String[] args) {
        Cake cake = new Cake.Builder("butter", "sugar").build();
        System.out.println(cake);
    }
}

class Cake {
   private String butter;
   private String sugar;
   private String p1;
   private String p2;
   private String p3;

   static class Builder {
       private String butter;
       private String sugar;
       private String p1;
       private String p2;
       private String p3;

       public Builder(String butter, String sugar) {
           this.butter = butter;
           this.sugar = sugar;
       }

       public Builder p1(String p1) {
           this.p1 = p1;
           return this;
       }

       public Cake build() {
           return new Cake(this);
       }


   }
    private Cake(Builder builder) {
        this.butter = builder.butter;
        this.sugar = builder.sugar;
        this.p1 = builder.p1;
        this.p2 = builder.p2;
        this.p3= builder.p3;
    }

    @Override
    public String toString() {
        return "Cake{" +
                "butter='" + butter + '\'' +
                ", sugar='" + sugar + '\'' +
                ", p1='" + p1 + '\'' +
                ", p2='" + p2 + '\'' +
                ", p3='" + p3 + '\'' +
                '}';
    }
}